package lambdasinaction.chap10;

import java.util.Optional;

import static java.util.Optional.empty;
import static java.util.Optional.of;

public class OperationsWithOptional {

    public static void main(String... args) {
        System.out.println(max(of(3), of(5)));
        System.out.println(max(empty(), of(5)));


        final Optional<Integer> integer = of(3).flatMap(a -> of(a + 1));

        final Optional<Integer> integer1 = of(2).map(a -> a + 1);
    }

    public static final Optional<Integer> max(Optional<Integer> i, Optional<Integer> j) {
        return i.flatMap(
                a -> j.map(
                        b -> Math.max(a, b)
                )
        );
    }
}

